package com.czk.classreader.method;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

import java.util.Objects;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/6 16:19
 */
public class ClassRemoveMethodVisitor extends ClassVisitor {
    private final String methodName;
    private final String methodDesc;

    public ClassRemoveMethodVisitor(int api, ClassVisitor classVisitor, String methodName, String methodDesc) {
        super(api, classVisitor);
        this.methodName = methodName;
        this.methodDesc = methodDesc;
    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        // 方法描述符和名称都相等表示同一个字方法
        if (Objects.equals(name,methodName)&&Objects.equals(methodDesc,descriptor)){
            // 这时候表示删除这个方法
            return null;
        }
        return super.visitMethod(access, name, descriptor, signature, exceptions);
    }
}
